package com.hyl.demo;

import java.io.UnsupportedEncodingException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.rocketmq.client.exception.MQClientException;

import com.hyl.msg.ActiveProducter;
import com.hyl.msg.KfkProducer;
import com.hyl.msg.RockConsumer;
import com.hyl.msg.RockProducer;

public class testpushmsg {
	public static void main(String[] msg) {
		//pushkfkamsg();
		//pushRockmsg();
		pushatvmsg();
	}

	//@Test
	public static void pushRockmsg() {
		RockProducer p = RockProducer.getInstance("pubgrp", "192.168.0.145:9876");
		try {
			p.pushMsg("topic1", "ab", "", "xxcc你好!412".getBytes("UTF-8"));
			//  Thread.sleep(10);
			p.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public static void pushkfkamsg() {
		KfkProducer p = new KfkProducer(null, null);
		try {
			for (int i = 0; i < 20; i++)
				p.pushMsg("testtopic", "a".getBytes(), "xxcc你好!".concat(String.valueOf(i)).getBytes());
			p.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public static void pushatvmsg() {
		ActiveProducter producter = new ActiveProducter();
		producter.init();
		testpushmsg testMq = new testpushmsg();
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		Runnable ra=new Runnable() {
			@Override
			public void run() {
				while (true) {
					try {
						producter.sendMessage("Jaycekon-MQ");
						Thread.sleep(10000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		};
		//Thread 1
		new Thread(ra).start();
		//Thread 2
		new Thread(ra).start();
		//Thread 3
		new Thread(ra).start();
		
	}



}
